#include "../include/parking.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(){
    parkingLot *lot = parking_create(1000);
    parking_search(lot);
    int spot_size;
    scanf("%d",&spot_size);
    parking_occur(lot,spot_size);
    parking_search(lot);
    free(lot->Parking_arr);
    free(lot);
    return 0;
}

parkingLot *parking_create(int size){
    parkingLot *parking_lot = (parkingLot *) malloc(sizeof (size));
    parking_lot->size = size;
    parking_lot->Parking_arr = (parkingSpot *) malloc(sizeof (parkingSpot)*size);
    if(parking_lot == NULL){
        return 0 ;
    }
    for(int i = 0;i < size;i++){
        parking_lot->Parking_arr[i].iID = i+1;
        parking_lot->Parking_arr[i].Parking_state = false;
    }
    return parking_lot;
}

bool parking_occur(parkingLot *Parking_lot,int iID){
    if(iID <= 0||iID > Parking_lot->size){
        printf("error\n");
        return false;
    }
    if(Parking_lot->Parking_arr[iID-1].Parking_state == 1){
        printf("false\n");
        return false;
    } else {
        Parking_lot->Parking_arr[iID-1].Parking_state = 1;
        printf("抢占停车位:%d\n",iID);
        return true;
    }
}


void parking_search(parkingLot *Parking_lot){
    for (int i = 0; i < Parking_lot->size; ++i)
    {
        if(Parking_lot->Parking_arr[i].Parking_state != 0){
            printf("车位有:%d",Parking_lot->Parking_arr[i].iID);
        }
    }
    printf("\n");

}

